package com.example.windowdemo.window.adapter;

import android.content.Context;
import android.view.View;

import com.example.windowdemo.callback.WindowAdapter;
import com.example.windowdemo.window.Window;
import com.example.windowdemo.window.builder.WindowBuilder;

/**
 * @author: njb
 * @date: 2023/8/2 17:45
 * @desc:
 */
public class WindowBuilderAdapter<T> implements WindowAdapter<T> {
    private WindowBuilder<T> builder;

    public WindowBuilderAdapter(WindowBuilder<T> builder) {
        this.builder = builder;
    }

    @Override
    public Window<T> createWindow(Context context) {
        return new Window<>(context);
    }

    @Override
    public void configureWindow(Window<T> window) {
        window.setFullScreen(builder.isFullScreen);
        window.setTitleBar(builder.hasTitleBar);
        window.setSize(builder.width, builder.height);
        window.setPosition(builder.x, builder.y);
        window.setGravity(builder.gravity);
        window.addView(builder.contentView);
    }

    @Override
    public void setData(Window<T> window, T data) {
        window.setData(data);
    }

    @Override
    public View createView(Context context) {
        return builder.contentView;
    }
}
